const Router = require('koa-router');

const router = new Router({
  prefix: '/api' //路由前缀
});

const fs = require('fs');
const path = require('path');

const files = fs.readdirSync(__dirname);

files
  .filter(file => file.endsWith('.js'))
  .forEach(file => {
    const file_name = file.substr(0, file.length - 3);
    const file_entity = require(path.join(__dirname, file));
    if (file_name !== 'index') {
      router.use(file_entity.routes()).use(file_entity.allowedMethods())
    }
  })

module.exports = router;
